package com.ctgu.server.controller;


import com.ctgu.server.dao.dto.AttendanceTimeSlotDto;
import com.ctgu.server.dao.dto.AttendanceUserDto;
import com.ctgu.server.dao.entity.AttendanceTimeSlot;
import com.ctgu.server.dao.vo.Result;
import com.ctgu.server.service.AttendanceTimeSlotService;
import com.ctgu.server.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 打卡时间段表 前端控制器
 * </p>
 *
 * @author ctgu
 * @since 2023-06-13
 */
@RestController
@RequestMapping("/server/attendanceTimeSlot")
@CrossOrigin
@Api(tags = "打卡信息操作接口")
public class AttendanceTimeSlotController {
    @Autowired
    private AttendanceTimeSlotService attendanceTimeSlotService;
    @ApiOperation(notes = "新增考勤组时间段",value = "新增考勤组时间段")
    @PostMapping("/insert")
    public Result addAttendanceTimeSlot(@RequestParam AttendanceTimeSlotDto attendanceTimeSlotDto){
        if(attendanceTimeSlotDto.getOpId()==null||attendanceTimeSlotDto.getAttGrId()==null||attendanceTimeSlotDto.getAttendanceTimeSlotList()==null){
            return ResultUtil.error("参数缺失！");
        }
        return attendanceTimeSlotService.addAttendanceTimeSlot(attendanceTimeSlotDto);
    }

//    @ApiOperation(notes = "删除考勤组时间段",value = "删除考勤组时间段")
//    @PostMapping("/delete")
//    public Result deleteAttendanceTimeSlot(@RequestParam AttendanceTimeSlotDto attendanceTimeSlotDto){
//        if(attendanceTimeSlotDto.getOpId()==null||attendanceTimeSlotDto.getAttGrId()==null||attendanceTimeSlotDto.getAttendanceTimeSlotList()==null){
//            return ResultUtil.error("参数缺失！");
//        }
//        return attendanceTimeSlotService.addAttendanceTimeSlot(attendanceTimeSlotDto);
//    }
    @ApiOperation(notes = "删除考勤组时间段",value = "删除考勤组时间段")
    @PostMapping("/delete")
    public Result deleteAllTimeSlot(@RequestParam AttendanceTimeSlotDto attendanceTimeSlotDto){
        if(attendanceTimeSlotDto.getOpId()==null||attendanceTimeSlotDto.getAttGrId()==null||attendanceTimeSlotDto.getAttendanceTimeSlotList()==null){
            return ResultUtil.error("参数缺失！");
        }
        boolean flag= attendanceTimeSlotService.deleteAll(attendanceTimeSlotDto.getOpId(),attendanceTimeSlotDto.getAttGrId());
        if(flag){
            return ResultUtil.success();
        }
        return ResultUtil.error("删除失败");
    }

    @ApiOperation(notes = "获取考勤组所有时间段",value = "获取所有考勤组所有考勤时间段")
    @PostMapping("/list")
    public Result listAllTimeSlot(@RequestParam String userId,@RequestParam String attGrId){
        if(userId==null||attGrId==null){
            return ResultUtil.error("参数缺失！");
        }
        List<AttendanceTimeSlot> attendanceTimeSlotList = attendanceTimeSlotService.listAllTimeSlot(userId,attGrId);

        return ResultUtil.success(attendanceTimeSlotList);
    }
}

